﻿using System.IO;
using System.Threading.Channels;
using System.Threading.Tasks;

namespace WYJ.Log.LogWriters
{

    /// <summary>
    /// Output To File —— OTF
    /// 往一个指定文件中添加文字内容。
    /// </summary>
    public sealed class OTFWriter : LinePassage<string>, ILogWriter
    {
        /// <summary>
        /// 文件路径和名称
        /// </summary>
        public string FileName { get; }
        public OTFWriter(string file) : base(Channel.CreateUnbounded<string>())
        {
            FileName = file;
        }


        protected override async Task Next(string msg)
        {
            await File.AppendAllTextAsync(FileName, msg);
        }
    }
}
